<%--
  Created by IntelliJ IDEA.
  User: carol
  Date: 2018/6/12
  Time: 17:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page language="java" import="java.util.*,javax.servlet.*,functest.*" pageEncoding="utf-8" %>
<html>
<head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="js/jquery-3-2-1.js"></script>
    <link type="text/css" rel="stylesheet" href="layui/css/layui.css" media="all">
    <script type="text/javascript" src="layui/layui.all.js"></script>
</head>
<body>
<div style="margin-left: 20px;margin-right: 20px">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>编辑航段</legend>
    </fieldset>
    <table lay-filter="hdtable">
        <thead>
        <tr>
            <th lay-data="{field:'hbname',align:'center'}">航班名</th>
            <th lay-data="{field:'sortid',align:'center',sort: true}">航段顺序</th>
            <th lay-data="{field:'startport',align:'center',sort: true}">起飞机场</th>
            <th lay-data="{field:'endport',align:'center',sort: true}">到达机场</th>
            <th lay-data="{field:'topprice',align:'center',sort: true}">头等舱价格</th>
            <th lay-data="{field:'ecoprice',align:'center',sort: true}">经济舱价格</th>
            <th lay-data="{fixed: 'right', minWidth: 120, align:'center', toolbar: '#barspxx'}">操作</th>
        </tr>
        </thead>
        <tbody>
        <%
            String hb_name = request.getParameter("hbname");
            FindAPrint func =new FindAPrint();
            List<Map<String,String>> airline=func.Findallhd(hb_name);
            for(Map<String,String> airlinemap:airline) {
                out.println("<tr><td>"+ airlinemap.get("hbname") +"</td><td>"
                        + airlinemap.get("sortid") +"</td><td>"
                        + airlinemap.get("startport") +"</td><td>"
                        + airlinemap.get("endport") +"</td><td>"
                        + airlinemap.get("topprice") +"</td><td>"
                        + airlinemap.get("ecoprice") +"</td><td>");
                out.println("</td><td></td></tr>");
            }
        %>
        </tbody>
    </table>
    <div style="text-align: center">
        <a class="layui-btn layui-btn-primary" href="handlehd.jsp?action=add&hbname=<%=hb_name%>">添加航段</a>
        <%
            if (airline.size() > 0){
        %>
        <a href="handlehd.jsp?action=del&hbname=<%=hb_name%>" class="layui-btn layui-btn-normal">删除（最后一个）</a>
        <%
            }
        %>
    </div>
</div>


</body>
</html>

<script type="text/html" id="barspxx">
    <a class="layui-btn layui-btn-radius layui-btn-xs" lay-event="edit">修改价格</a>
</script>
<script type="text/javascript">
    layui.use(['jquery','layer','table'], function(){
        var layer = layui.layer
            ,element = layui.element
            ,$= layui.$
            ,table=layui.table;

        //转换静态表格
        table.init('hdtable', {cellMinWidth: 120,limit: 10,page:true});
        //监听工具条
        table.on('tool(hdtable)', function(obj){
            var data = obj.data;
            var sortid = data['sortid'];
            var editurl = 'handlehd.jsp?action=edit&hbname=<%=hb_name%>&sortid='+sortid;
            if(obj.event === 'edit'){
                layer.open({
                    type: 2,
                    title: "编辑航段价格",
                    content: editurl,
                    area: [window.innerWidth * 1.5 / 3 + "px", window.innerHeight * 26 / 30 + "px"],
                });
            }
        });
    });
</script>
